import { get } from '../../utils/request'
const actions = {
  // 查询所有订单信息
  findAllOrder(context, list) {
    // 异步操作
    get("/order/pageQuery", list).then(res => {
      let response = res.data.list
      let total = res.data.total
      for (let item of response) {
        if (item.status === "待派单") {
          item.type = "success";
        } else if (item.status === "待接单") {
          item.type = "warning";
        } else if (item.status === "待服务"){
          item.type = "info";
        }else{
          item.type = null;
        }
        if (!item.employeeId) {
          item.employeeId = '--'
        }
      }
      context.commit('SET_ORDERS', response)
      context.commit('SET_TOTAL', total)
    })
  },
  // 查询可派单的人员
  querySendPerson(context, list) {
    get("/baseUser/pageQuery", list).then((res) => {
      let employeeList = res.data.list;
      context.commit('SET_EMPLOYEELIST', employeeList)
    });
  },
}
const mutations = {
  //修改state中的值
  SET_ORDERS(state, response) {
    state.orders = response
  },
  SET_TOTAL(state, total) {
    state.total = total
  },
  SET_EMPLOYEELIST(state, employeeList) {
    state.employeeList = employeeList
  },
}
const state = {
  orders: [],
  total: 0,
  employeeList: [],
}

export default {
  namespaced: true,
  state,
  actions,
  mutations,
}